FROM java:8-jdk

LABEL maintainer="Roy Kim <roy.kim@navercorp.com>"

ARG PINPOINT_VERSION=${PINPOINT_VERSION:-2.2.0}

ENV HBASE_VERSION=1.2.6
ENV BASE_DIR=/opt/hbase
ENV HBASE_HOME=${BASE_DIR}/hbase-${HBASE_VERSION}

COPY hbase-site.xml hbase-site.xml
COPY hbase-env.sh hbase-env.sh
COPY /build/scripts/initialize-hbase.sh /usr/local/bin/
COPY /build/scripts/check-table.sh /usr/local/bin/
COPY /hbase-create.hbase ${BASE_DIR}/
COPY /hbase-${HBASE_VERSION}-bin.tar.gz ${BASE_DIR}/hbase.tar.gz

RUN chmod a+x /usr/local/bin/initialize-hbase.sh \
    && chmod a+x /usr/local/bin/check-table.sh \
    && cd ${BASE_DIR} \
    && tar xfz hbase.tar.gz \
    && mv ../../hbase-site.xml ../../${HBASE_HOME}/conf/hbase-site.xml \
    && mv ../../hbase-env.sh ../../${HBASE_HOME}/conf/hbase-env.sh \
    && ${HBASE_HOME}/bin/start-hbase.sh \
    && sleep 10 \
    && ${HBASE_HOME}/bin/hbase shell ${BASE_DIR}/hbase-create.hbase \
    && ${HBASE_HOME}/bin/stop-hbase.sh \
    && rm ${BASE_DIR}/hbase-create.hbase \
    && rm -rf hbase.tar.gz

VOLUME ["/home/pinpoint/hbase", "/home/pinpoint/zookeeper"]

ENTRYPOINT ${BASE_DIR}/hbase-${HBASE_VERSION}/bin/hbase master start

